﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>OnEvent (GUI) - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The OnEvent method of a Gui or GuiControl object registers a function or method to be called when the given event is raised by a GUI window or control." />
<meta name="ahk:equiv-v1" content="commands/Gui.htm#Labels" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css">
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>OnEvent</h1>
<p>Registers a function or method to be called when the given event is raised by a GUI window or control.</p>
<pre class="Syntax">Object.<span class="func">OnEvent</span>(EventName, Callback <span class="optional">, AddRemove := 1</span>)</pre>

<h2>参数</h2>
<dl>
  <dt>Object</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#objects">对象</a></p>
    <p>A <a href="Gui.htm">Gui</a> or <a href="GuiControl.htm">GuiControl</a> object.</p>
  </dd>
  
  <dt>EventName</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The name of the event.</p>
  </dd>
  
  <dt>Callback</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a> or <a href="../Concepts.htm#objects">Object</a></p>
    <p>The function, method or object to call when the event is raised.</p>
    <p>If this parameter is a string, its meaning depends on whether the GUI has an <a href="../objects/Gui.htm#EventObj">event sink</a> (that is, whether <a href="../objects/Gui.htm#New">Gui.New</a>'s <em>EventObj</em> parameter was specified). If the GUI has an event sink, the string must be the name of a method belonging to the event sink; otherwise, it must be the name of a function.</p>
    <p>To register a function regardless of whether the GUI has an event sink, pass a <a href="Func.htm">function reference</a>.</p>
  </dd>
  
  <dt>AddRemove</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>One of the following values:<br>
    <strong>1</strong> (the default): Call the callback after any previously registered callbacks.<br>
    <strong>-1</strong>: Call the callback before any previously registered callbacks.<br>
    <strong>0</strong>: Do not call the callback.</p>
  </dd>
</dl>

<h2 id="Callback_Parameters">Callback Parameters</h2>
<p>If the callback is a method registered by name, its hidden <a href="../Objects.htm#Custom_Classes_method"><em>this</em> parameter</a> seamlessly receives the event sink object (that is, the object to which the method belongs). This parameter is not shown in the parameter lists in this documentation.</p>
<p>Since <em>Callback</em> can be an object, it can be a <a href="Functor.htm#BoundFunc">BoundFunc object</a> which inserts additional parameters at the beginning of the parameter list and then calls another function. This is a general technique not specific to OnEvent, so is generally ignored by the rest of this documentation.</p>
<p>The callback's first explicit parameter is <em>Object</em>; i.e. the <a href="Gui.htm">Gui</a> or <a href="GuiControl.htm">GuiControl</a> object which raised the event. The only exception is that this parameter is omitted when a Gui <a href="Gui.htm#EventObj">handles its own events</a>, since <code>this</code> already contains a reference to the Gui.</p>
<p>Many events pass additional parameters about the event, as described for each event.</p>
<p>As with all methods or functions called dynamically, the callback is not required to declare parameters which the callback itself does not need, but in this case an asterisk must be specified as the final parameter. If an event has more parameters than are declared by the callback, they will simply be ignored (unless the callback is <a href="../Functions.htm#Variadic">variadic</a>).</p>
<p>The callback can declare more parameters than the event provides if (and only if) the additional parameters are declared optional. However, the use of optional parameters is not recommended as future versions of the program may extend an event with additional parameters, in which case the optional parameters would stop receiving their default values.</p>

<h2 id="Callback_Return_Value">Callback Return Value</h2>
<p>If multiple callbacks have been registered for an event, a callback may return a non-empty value to prevent any remaining callbacks from being called.</p>
<p>The return value may have additional meaning for specific events. 例如, a <a href="#Close">Close</a> callback may return a non-zero number (such as <code>true</code>) to prevent the GUI window from closing.</p>

<h2 id="Callback_Name">Callback Name</h2>
<p>By convention, the syntax of each event below is shown with a function name of the form <code><i>ObjectType</i>_<i>EventName</i></code>, for clarity. Scripts are not required to follow this convention, and can use any valid function name.</p>

<h2 id="Threads">Threads</h2>
<p>Each event callback is called in a new <a href="../misc/Threads.htm">thread</a>, and therefore starts off fresh with the default values for settings such as <a href="../commands/SendMode.htm">SendMode</a>. These defaults can be changed in the <a href="../Scripts.htm#auto">script startup</a>.</p>
<p>Whenever a GUI <a href="../misc/Threads.htm">thread</a> is launched, that thread's <a href="../misc/WinTitle.htm#LastFoundWindow">last found window</a> starts off as the GUI window itself. This allows functions for windows and controls -- such as <a href="../commands/WinGetStyle.htm">WinGetStyle</a>, <a href="../commands/WinSetTransparent.htm">WinSetTransparent</a>, and <a href="../commands/ControlGetFocus.htm">ControlGetFocus</a> -- to omit WinTitle and WinText when operating upon the GUI window itself (even if it is hidden).</p>
<p>Except where noted, each event is limited to one thread at a time, per object. If an event is raised before a previous thread started by that event finishes, it is usually discarded. To prevent this, use <a href="../commands/Critical.htm">Critical</a> as the callback's first line (however, this will also buffer/defer other <a href="../misc/Threads.htm">threads</a> such as the press of a hotkey).</p>

<h2 id="Destroying_the_GUI">Destroying the GUI</h2>
<p>When a GUI is destroyed, all event callbacks are released. Therefore, if the GUI is destroyed while an event is being dispatched, subsequent event callbacks are not called. For clarity, callbacks should <a href="#Callback_Return_Value">return a non-empty value</a> after destroying the GUI.</p>

<h2 id="Events">Events</h2>
<p>The following events are supported by <a href="Gui.htm">Gui</a> objects:</p>
<table class="info" id="Window_Events">
  <tr><th>Event</th><th>Raised when...</th></tr>
  <tr><td><a href="#Close">Close</a></td><td>The window is closed.</td></tr>
  <tr><td><a href="#ContextMenu">ContextMenu</a></td><td>The user right-clicks within the window or presses the <kbd>Menu</kbd> key or <kbd>Shift</kbd>+<kbd>F10</kbd>.</td></tr>
  <tr><td><a href="#DropFiles">DropFiles</a></td><td>Files/folders are dragged and dropped onto the window.</td></tr>
  <tr><td><a href="#Escape">Escape</a></td><td>The user presses the Escape key while the GUI window is active.</td></tr>
  <tr><td><a href="#Size">Size</a></td><td>The window is resized, minimized, maximized or restored.</td></tr>
</table>
<p>The following events are supported by <a href="GuiControl.htm">GuiControl</a> objects, depending on the control type:</p>
<table class="info" id="Control_Events">
  <tr><th>Event</th><th>Raised when...</th></tr>
  <tr><td><a href="#Change">Change</a></td><td>The control's value changes.</td></tr>
  <tr><td><a href="#Click">Click</a></td><td>The control is clicked.</td></tr>
  <tr><td><a href="#DoubleClick">DoubleClick</a></td><td>The control is double-clicked.</td></tr>
  <tr><td><a href="#ColClick">ColClick</a></td><td>One of the ListView's column headers is clicked.</td></tr>
  <tr><td><a href="#Ctrl-ContextMenu">ContextMenu</a></td><td>The user right-clicks the control or presses the <kbd>Menu</kbd> key or <kbd>Shift</kbd>+<kbd>F10</kbd> while the control has the keyboard focus.</td></tr>
  <tr><td><a href="#Focus">Focus</a></td><td>The control gains the keyboard focus.</td></tr>
  <tr><td><a href="#LoseFocus">LoseFocus</a></td><td>The control loses the keyboard focus.</td></tr>
  <tr><td><a href="#ItemCheck">ItemCheck</a></td><td>A ListView or TreeView item is checked or unchecked.</td></tr>
  <tr><td><a href="#ItemEdit">ItemEdit</a></td><td>A ListView or TreeView item's label is edited by the user.</td></tr>
  <tr><td><a href="#ItemExpand">ItemExpand</a></td><td>A TreeView item is expanded or collapsed.</td></tr>
  <tr><td><a href="#ItemFocus">ItemFocus</a></td><td>The focused item changes in a ListView.</td></tr>
  <tr><td><a href="#ItemSelect">ItemSelect</a></td><td>A ListView or TreeView item is selected, or a ListView item is deselected.</td></tr>
</table>

<h2>Window Events</h2>

<h3 id="Close">Close</h3>
<p>Launched when the user or another program attempts to close the window, such as by pressing the X button in its title bar, selecting "Close" from its system menu, or calling <a href="../commands/WinClose.htm">WinClose</a>.</p>
<pre class="Syntax">Gui_<span class="func">Close</span>(GuiObj)</pre>
<p>By default, the window is automatically hidden after the callback returns, or if no callbacks were registered. A callback can prevent this by returning 1 (or <code>true</code>), which will also prevent any remaining callbacks from being called. The callback can hide the window immediately by calling <a href="Gui.htm#Hide">Gui.Hide</a>, or destroy the window by calling <a href="Gui.htm#Destroy">Gui.Destroy</a>.</p>
<p>例如, this GUI shows a confirmation prompt before closing:</p>
<pre>myGui := Gui.New()
myGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
myGui.OnEvent("Close", "myGui_Close")
myGui_Close(thisGui) {  <em>; Declaring this parameter is optional.</em>
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  <em>; true = 1</em>
}
myGui.Show</pre>

<h3 id="ContextMenu">ContextMenu</h3>
<p>Launched whenever the user right-clicks anywhere in the window except the title bar and menu bar.  It is also launched in response to pressing the <kbd>Menu</kbd> key or <kbd>Shift</kbd>+<kbd>F10</kbd>.</p>
<pre class="Syntax">Gui_<span class="func">ContextMenu</span>(GuiObj, GuiCtrlObj, Item, IsRightClick, X, Y)</pre>
<dl><dt>GuiCtrlObj</dt><dd><p>The <a href="GuiControl.htm">GuiControl object</a> of the control that received the event (blank if none).</p></dd>
  <dt>Item</dt><dd>
    <p>When a ListBox, ListView, or TreeView is the target of the context menu (as determined by <em>GuiCtrlObj</em>), <em>Item</em> specifies which of the control's items is the target.</p>
    <p><a href="../commands/GuiControls.htm#ListBox">ListBox</a>: The number of the currently focused row. Note that a standard ListBox does not focus an item when it is right-clicked, so this might not be the clicked item.</p>
    <p><a href="../commands/ListView.htm">ListView</a> and <a href="../commands/TreeView.htm">TreeView</a>: For right-clicks, <em>Item</em> contains the clicked item's ID or row number (or 0 if the user clicked somewhere other than an item). For the AppsKey and Shift-F10, <em>Item</em> contains the selected item's ID or row number.</p></dd>
  <dt>IsRightClick</dt><dd>
    <p><code>True</code> if the user clicked the right mouse button.<br>
    <code>False</code> if the user pressed the <kbd>Menu</kbd> key or <kbd>Shift</kbd>+<kbd>F10</kbd>.</p></dd>
  <dt>X, Y</dt><dd><p>The X and Y coordinates of where the script should display the menu (e.g. <code>MyContextMenu.<a href="../objects/Menu.htm#Show">Show</a> X, Y</code>). Coordinates are relative to the upper-left corner of the window's client area.</p></dd>
</dl>
<p>Unlike most other GUI events, the ContextMenu event can have more than one concurrent <a href="../misc/Threads.htm">thread</a>.</p>
<p>Each control can have its own ContextMenu event callback which is called before any callback registered for the Gui object. Control-specific callbacks omit the <em>GuiObj</em> parameter, but all other parameters are the same.</p>
<p>Note: Since <a href="../commands/GuiControls.htm#Edit">Edit</a> and <a href="../commands/GuiControls.htm#MonthCal">MonthCal</a> controls have their own context menu, a right-click in one of them will not launch the ContextMenu event.</p>

<h3 id="DropFiles">DropFiles</h3>
<p>Launched whenever files/folders are dropped onto the window as part of a drag-and-drop operation (but if this callback is already running, drop events are ignored).</p>
<pre class="Syntax">Gui_<span class="func">DropFiles</span>(GuiObj, GuiCtrlObj, FileArray, X, Y)</pre>
<dl>
  <dt>GuiCtrlObj</dt>
  <dd><p>The <a href="GuiControl.htm">GuiControl object</a> of the control upon which the files were dropped (blank if none).</p></dd>

  <dt>FileArray</dt>
  <dd><p>An <a href="../Objects.htm#Usage_Simple_Arrays">array (object)</a> of filenames, where <code>FileArray[1]</code> is the first file and <code>FileArray.Length</code> returns the number of files. A <a href="../commands/For.htm">for-loop</a> can be used to iterate through the files:</p>
<pre>Gui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
    for i, file in FileArray
        MsgBox "File " i " is:`n" file
}</pre></dd>

  <dt>X, Y</dt>
  <dd><p>The X and Y coordinates of where the files were dropped, relative to the upper-left corner of the window's client area.</p></dd>
</dl>

<h3 id="Escape">Escape</h3>
<p>Launched when the user presses the <kbd>Escape</kbd> key while the GUI window is active.</p>
<pre class="Syntax">Gui_<span class="func">Escape</span>(GuiObj)</pre>
<p>By default, pressing the <kbd>Escape</kbd> key has no effect. Known limitation: If the first control in the window is disabled (possibly depending on control type), the Escape event will not be launched. There may be other circumstances that produce this effect.</p>

<h3 id="Size">Size</h3>
<p>Launched when the window is resized, minimized, maximized, or restored.</p>
<pre class="Syntax">Gui_<span class="func">Size</span>(GuiObj, MinMax, Width, Height)</pre>
<dl>
  <dt>MinMax</dt><dd><p>One of the following values:</p>
    <p>0: The window is neither minimized nor maximized.<br>
       1: The window is maximized.<br>
      -1: The window is minimized.</p>
    <p>Note that a maximized window can be resized without restoring/un-maximizing it, so a value of 1 does not necessarily mean that this event was raised in response to the user maximizing the window.</p></dd>
  <dt>Width, Height</dt><dd>The new width and height of the window's client area, which is the area excluding title bar, menu bar, and borders.</dd>
</dl>
<p>A script may use the Size event to reposition and resize controls in response to the user's resizing of the window.</p>
<p>When the window is resized (even by the script), the Size event might not be raised immediately. As with other window events, if the current thread is <a href="../commands/Thread.htm#Interrupt">uninterruptible</a>, the Size event won't be raised until the thread becomes interruptible. If the script has just resized the window, follow this example to ensure the Size event is raised immediately:</p>
<pre><a href="../commands/Critical.htm#Off">Critical</a> "Off"  <em>; Even if Critical "On" was never used.</em>
<a href="../commands/Sleep.htm">Sleep</a> -1</pre>
<p><a href="Gui.htm#Show">Gui.Show</a> automatically does a <code>Sleep -1</code>, so it is generally not necessary to call Sleep in that case.</p>

<h2>Control Events</h2>

<h3 id="Change">Change</h3>
<p>Raised when the control's value changes.</p>
<pre class="Syntax">Ctrl_<span class="func">Change</span>(GuiCtrlObj, Info)</pre>
<dl>
  <dt>Info</dt>
  <dd>
    <p>For <a href="../commands/GuiControls.htm#Slider">Slider</a> controls, <em>Info</em> is a numeric value indicating how the slider moved. For details, 请参阅 <a href="../commands/GuiControls.htm#slider-change">Detecting Changes (Slider)</a>.</p>
    <p>For all other controls, <em>Info</em> currently has no meaning.</p>
  </dd>
</dl>
<p>To retrieve the control's new value, use <a href="GuiControl.htm#Value">GuiCtrlObj.Value</a>.</p>
<p>Applies to: <a href="../commands/GuiControls.htm#DDL">DDL</a>, <a href="../commands/GuiControls.htm#ComboBox">ComboBox</a>, <a href="../commands/GuiControls.htm#ListBox">ListBox</a>, <a href="../commands/GuiControls.htm#Edit">Edit</a>, <a href="../commands/GuiControls.htm#DateTime">DateTime</a>, <a href="../commands/GuiControls.htm#MonthCal">MonthCal</a>, <a href="../commands/GuiControls.htm#Hotkey">Hotkey</a>, <a href="../commands/GuiControls.htm#UpDown">UpDown</a>, <a href="../commands/GuiControls.htm#Slider">Slider</a>, <a href="../commands/GuiControls.htm#Tab">Tab</a>.</p>

<h3 id="Click">Click</h3>
<p>Raised when the control is clicked.</p>
<pre class="Syntax">Ctrl_<span class="func">Click</span>(GuiCtrlObj, Info)
Link_<span class="func">Click</span>(GuiCtrlObj, Info, Href)</pre>
<dl>
  <dt>Info</dt>
  <dd>
    <p>ListView: The row number of the clicked item, or 0 if the mouse was not over an item.</p>
    <p>TreeView: The ID of the clicked item, or 0 if the mouse was not over an item.</p>
    <p>Link: The link's ID attribute (a string) if it has one, otherwise the link's index (an integer).</p>
    <p>StatusBar: The part number of the clicked section (however, the part number might be a very large integer if the user clicks near the sizing grip at the right side of the bar).</p>
    <p>For all other controls, <em>Info</em> currently has no meaning.</p>
  </dd>
  <dt>Href</dt>
  <dd><p>Link: The link's HREF attribute. Note that if a Click event callback is registered, the HREF attribute is not automatically executed.</p></dd>
</dl>
<p>Applies to: <a href="../commands/GuiControls.htm#Text">Text</a>, <a href="../commands/GuiControls.htm#Pic">Pic</a>, <a href="../commands/GuiControls.htm#Button">Button</a>, <a href="../commands/GuiControls.htm#Checkbox">CheckBox</a>, <a href="../commands/GuiControls.htm#Radio">Radio</a>, <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>, <a href="../commands/GuiControls.htm#Link">Link</a>, <a href="../commands/GuiControls.htm#StatusBar">StatusBar</a>.</p>

<h3 id="DoubleClick">DoubleClick</h3>
<p>Raised when the control is double-clicked.</p>
<pre class="Syntax">Ctrl_<span class="func">DoubleClick</span>(GuiCtrlObj, Info)</pre>
<dl>
  <dt>Info</dt>
  <dd>
    <p>ListView, TreeView and StatusBar: Same as for the <a href="../objects/GuiOnEvent.htm#Click">Click</a> event.</p>
    <p>ListBox: The position of the focused item. Double-clicking empty space below the last item usually focuses the last item and leaves the selection as it was.</p>
  </dd>
</dl>
<p>Applies to: <a href="../commands/GuiControls.htm#Text">Text</a>, <a href="../commands/GuiControls.htm#Pic">Pic</a>, <a href="../commands/GuiControls.htm#Button">Button</a>, <a href="../commands/GuiControls.htm#Checkbox">CheckBox</a>, <a href="../commands/GuiControls.htm#Radio">Radio</a>, <a href="../commands/GuiControls.htm#ComboBox">ComboBox</a>, <a href="../commands/GuiControls.htm#ListBox">ListBox</a>, <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>, <a href="../commands/GuiControls.htm#StatusBar">StatusBar</a>.</p>

<h3 id="ColClick">ColClick</h3>
<p>Raised when one of the ListView's column headers is clicked.</p>
<pre class="Syntax">Ctrl_<span class="func">ColClick</span>(GuiCtrlObj, Info)</pre>
<dl>
  <dt>Info</dt>
  <dd><p>The one-based column number that was clicked. This is the original number assigned when the column was created; that is, it does not reflect any dragging and dropping of columns done by the user.</p></dd>
</dl>
<p>Applies to: <a href="../commands/ListView.htm">ListView</a>.</p>

<h3 id="Ctrl-ContextMenu">ContextMenu</h3>
<p>Raised when the user right-clicks the control or presses the <kbd>Menu</kbd> key or <kbd>Shift</kbd>+<kbd>F10</kbd> while the control has the keyboard focus.</p>
<pre class="Syntax">Ctrl_<span class="func">ContextMenu</span>(GuiCtrlObj, Item, IsRightClick, X, Y)</pre>
<p>For details, 请参阅 <a href="#ContextMenu">ContextMenu</a>.</p>
<p>Applies to: All controls except Edit and MonthCal (and the Edit control within a ComboBox), which have their own standard context menu.</p>

<span id="LoseFocus"></span><h3 id="Focus">Focus / LoseFocus</h3>
<p>Raised when the control gains or loses the keyboard focus.</p>
<pre class="Syntax">Ctrl_<span class="func">Focus</span>(GuiCtrlObj, Info)
Ctrl_<span class="func">LoseFocus</span>(GuiCtrlObj, Info)</pre>
<dl>
  <dt>Info</dt>
  <dd><p>Reserved.</p></dd>
</dl>
<p>Applies to: <a href="../commands/GuiControls.htm#Button">Button</a>, <a href="../commands/GuiControls.htm#Checkbox">CheckBox</a>, <a href="../commands/GuiControls.htm#Radio">Radio</a>, <a href="../commands/GuiControls.htm#DDL">DDL</a>, <a href="../commands/GuiControls.htm#ComboBox">ComboBox</a>, <a href="../commands/GuiControls.htm#ListBox">ListBox</a>, <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>, <a href="../commands/GuiControls.htm#Edit">Edit</a>, <a href="../commands/GuiControls.htm#DateTime">DateTime</a>.</p>
<p>Not supported: <a href="../commands/GuiControls.htm#Hotkey">Hotkey</a>, <a href="../commands/GuiControls.htm#Slider">Slider</a>, <a href="../commands/GuiControls.htm#Tab">Tab</a> and <a href="../commands/GuiControls.htm#Link">Link</a>. Note that <a href="../commands/GuiControls.htm#Text">Text</a>, <a href="../commands/GuiControls.htm#Pic">Pic</a>, <a href="../commands/GuiControls.htm#MonthCal">MonthCal</a>, <a href="../commands/GuiControls.htm#UpDown">UpDown</a> and <a href="../commands/GuiControls.htm#StatusBar">StatusBar</a> controls do not accept the keyboard focus.</p>

<h3 id="ItemCheck">ItemCheck</h3>
<p>Raised when a ListView or TreeView item is checked or unchecked.</p>
<pre class="Syntax">Ctrl_<span class="func">ItemCheck</span>(GuiCtrlObj, Item, Checked)</pre>
<p>Applies to: <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>.</p>

<h3 id="ItemEdit">ItemEdit</h3>
<p>Raised when a ListView or TreeView item's label is edited by the user.</p>
<pre class="Syntax">Ctrl_<span class="func">ItemEdit</span>(GuiCtrlObj, Item)</pre>
<p>An item's label can only be edited if <code>-ReadOnly</code> has been used in the control's options.</p>
<p>Applies to: <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>.</p>

<h3 id="ItemExpand">ItemExpand</h3>
<p>Raised when a TreeView item is expanded or collapsed.</p>
<pre class="Syntax">Ctrl_<span class="func">ItemExpand</span>(GuiCtrlObj, Item, Expanded)</pre>
<p>Applies to: <a href="../commands/TreeView.htm">TreeView</a>.</p>

<h3 id="ItemFocus">ItemFocus</h3>
<p>Raised when the focused item changes in a ListView.</p>
<pre class="Syntax">Ctrl_<span class="func">ItemFocus</span>(GuiCtrlObj, Item)</pre>
<p>Applies to: <a href="../commands/ListView.htm">ListView</a>.</p>

<h3 id="ItemSelect">ItemSelect</h3>
<p>Raised when a ListView or TreeView item is selected, or a ListView item is deselected.</p>
<pre class="Syntax">ListView_<span class="func">ItemSelect</span>(GuiCtrlObj, Item, Selected)
TreeView_<span class="func">ItemSelect</span>(GuiCtrlObj, Item)</pre>
<p>Applies to: <a href="../commands/ListView.htm">ListView</a>, <a href="../commands/TreeView.htm">TreeView</a>.</p>
<p>ListView: This event is raised once for each item being deselected or selected, so can be raised multiple times in response to a single action by the user.</p>


<h2 id="Other_Events">Other Events</h2>
<p>Other types of GUI events can be detected and acted upon via <a href="GuiOnNotify.htm">OnNotify</a>, <a href="GuiOnCommand.htm">OnCommand</a> or <a href="../commands/OnMessage.htm">OnMessage</a>. 例如, a script can display context-sensitive help via ToolTip whenever the user moves the mouse over particular controls in the window. This is demonstrated in the <a href="Gui.htm#ExToolTip">GUI ToolTip example</a>.</p>


</body>
</html>